package com.github.catvod.spider.merge;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class qd extends ImageView {
  public boolean V0 = false;
  
  private String h;
  
  private Handler j = new Tw(this);
  
  public qd(Context paramContext) {
    super(paramContext);
  }
  
  public int BQ() {
    DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
    ViewGroup.LayoutParams layoutParams = getLayoutParams();
    int j = getHeight();
    int i = j;
    if (j <= 0)
      i = layoutParams.height; 
    j = i;
    if (i <= 0)
      j = getMaxHeight(); 
    i = j;
    if (j <= 0)
      i = displayMetrics.heightPixels; 
    Log.e("ImageView实际的高度", String.valueOf(i));
    return i;
  }
  
  public int I(BitmapFactory.Options paramOptions) {
    int m = W();
    int i = BQ();
    int j = paramOptions.outWidth;
    Log.e("网络图片实际的宽度", String.valueOf(j));
    int k = paramOptions.outHeight;
    Log.e("网络图片实际的高度", String.valueOf(k));
    if (j > m || k > i) {
      j = Math.round((j / m));
      k = Math.round((k / i));
      i = k;
      if (j > k)
        i = j; 
      Log.e("压缩比率", String.valueOf(i));
      return i;
    } 
    i = 1;
    Log.e("压缩比率", String.valueOf(i));
    return i;
  }
  
  public void Qy() {
    File file = new File(getContext().getCacheDir(), oC());
    if (file.length() > 0L) {
      try {
        FileInputStream fileInputStream = new FileInputStream();
        this(file);
        Bitmap bitmap = q(fileInputStream);
        Message message = Message.obtain();
        message.obj = bitmap;
        message.what = 1;
        this.j.sendMessage(message);
        Log.e("MyImageView", "使用缓存图片");
      } catch (FileNotFoundException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
      } 
    } else {
      oq();
      Log.e("MyImageView", "使用网络图片");
    } 
  }
  
  public int W() {
    DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
    ViewGroup.LayoutParams layoutParams = getLayoutParams();
    int i = getWidth();
    int j = i;
    if (i <= 0)
      j = layoutParams.width; 
    i = j;
    if (j <= 0)
      i = getMaxWidth(); 
    j = i;
    if (i <= 0)
      j = displayMetrics.widthPixels; 
    Log.e("ImageView实际的宽度", String.valueOf(j));
    return j;
  }
  
  public void j(InputStream paramInputStream) {
    try {
      File file = new File();
      this(getContext().getCacheDir(), oC());
      FileOutputStream fileOutputStream = new FileOutputStream();
      this(file);
      byte[] arrayOfByte = new byte[1024];
      while (true) {
        int i = paramInputStream.read(arrayOfByte);
        if (i != -1) {
          fileOutputStream.write(arrayOfByte, 0, i);
          continue;
        } 
        fileOutputStream.close();
        Log.e("MyImageView", "缓存成功");
        return;
      } 
    } catch (IOException iOException) {
      iOException.printStackTrace();
      Log.e("MyImageView", "缓存失败");
    } 
  }
  
  public String oC() {
    StringBuilder stringBuilder1 = new StringBuilder();
    String[] arrayOfString = this.h.split("\\/");
    int i = arrayOfString.length;
    for (byte b = 0; b < i; b++)
      stringBuilder1.append(arrayOfString[b]); 
    StringBuilder stringBuilder2 = new StringBuilder();
    stringBuilder2.append("文件名：");
    stringBuilder2.append(stringBuilder1.toString());
    Log.e("MyImageView", stringBuilder2.toString());
    return stringBuilder1.toString();
  }
  
  public void oq() {
    (new yh(this)).start();
  }
  
  public Bitmap q(InputStream paramInputStream) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
      byte[] arrayOfByte = new byte[1024];
      while (true) {
        int i = paramInputStream.read(arrayOfByte);
        if (i > -1) {
          byteArrayOutputStream.write(arrayOfByte, 0, i);
          continue;
        } 
        byteArrayOutputStream.flush();
        paramInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ByteArrayInputStream byteArrayInputStream1 = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(paramInputStream, null, options);
        options.inSampleSize = I(options);
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeStream(byteArrayInputStream1, null, options);
      } 
    } catch (IOException iOException) {
      iOException.printStackTrace();
    } 
    paramInputStream = new ByteArrayInputStream(options.toByteArray());
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(options.toByteArray());
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(paramInputStream, null, options);
    options.inSampleSize = I(options);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeStream(byteArrayInputStream, null, options);
  }
  
  public void u(String paramString) {
    this.h = paramString;
    if (this.V0) {
      Qy();
    } else {
      oq();
    } 
  }
  
  class Tw extends Handler {
    final qd h;
    
    Tw(qd this$0) {}
    
    public void handleMessage(Message param1Message) {
      int i = param1Message.what;
      if (i != 1) {
        if (i != 2) {
          if (i == 3)
            Toast.makeText(this.h.getContext(), "服务器发生错误", 0).show(); 
        } else {
          Toast.makeText(this.h.getContext(), "网络连接失败", 0).show();
        } 
      } else {
        Bitmap bitmap = (Bitmap)param1Message.obj;
        this.h.setImageBitmap(bitmap);
      } 
    }
  }
  
  class yh extends Thread {
    final qd h;
    
    yh(qd this$0) {}
    
    public void run() {
      // Byte code:
      //   0: new java/net/URL
      //   3: astore_2
      //   4: aload_2
      //   5: aload_0
      //   6: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   9: invokestatic h : (Lcom/github/catvod/spider/merge/qd;)Ljava/lang/String;
      //   12: invokespecial <init> : (Ljava/lang/String;)V
      //   15: aload_2
      //   16: invokevirtual openConnection : ()Ljava/net/URLConnection;
      //   19: checkcast java/net/HttpURLConnection
      //   22: astore_2
      //   23: aload_2
      //   24: ldc 'GET'
      //   26: invokevirtual setRequestMethod : (Ljava/lang/String;)V
      //   29: aload_2
      //   30: sipush #10000
      //   33: invokevirtual setConnectTimeout : (I)V
      //   36: aload_2
      //   37: invokevirtual getResponseCode : ()I
      //   40: sipush #200
      //   43: if_icmpne -> 208
      //   46: aload_2
      //   47: invokevirtual getInputStream : ()Ljava/io/InputStream;
      //   50: astore_3
      //   51: aload_0
      //   52: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   55: astore_2
      //   56: aload_2
      //   57: getfield V0 : Z
      //   60: ifeq -> 165
      //   63: new java/io/ByteArrayOutputStream
      //   66: astore_2
      //   67: aload_2
      //   68: invokespecial <init> : ()V
      //   71: sipush #1024
      //   74: newarray byte
      //   76: astore #4
      //   78: aload_3
      //   79: aload #4
      //   81: invokevirtual read : ([B)I
      //   84: istore_1
      //   85: iload_1
      //   86: iconst_m1
      //   87: if_icmple -> 101
      //   90: aload_2
      //   91: aload #4
      //   93: iconst_0
      //   94: iload_1
      //   95: invokevirtual write : ([BII)V
      //   98: goto -> 78
      //   101: aload_2
      //   102: invokevirtual flush : ()V
      //   105: goto -> 115
      //   108: astore #4
      //   110: aload #4
      //   112: invokevirtual printStackTrace : ()V
      //   115: new java/io/ByteArrayInputStream
      //   118: astore #5
      //   120: aload #5
      //   122: aload_2
      //   123: invokevirtual toByteArray : ()[B
      //   126: invokespecial <init> : ([B)V
      //   129: new java/io/ByteArrayInputStream
      //   132: astore #4
      //   134: aload #4
      //   136: aload_2
      //   137: invokevirtual toByteArray : ()[B
      //   140: invokespecial <init> : ([B)V
      //   143: aload_0
      //   144: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   147: aload #5
      //   149: invokevirtual q : (Ljava/io/InputStream;)Landroid/graphics/Bitmap;
      //   152: astore_2
      //   153: aload_0
      //   154: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   157: aload #4
      //   159: invokevirtual j : (Ljava/io/InputStream;)V
      //   162: goto -> 171
      //   165: aload_2
      //   166: aload_3
      //   167: invokevirtual q : (Ljava/io/InputStream;)Landroid/graphics/Bitmap;
      //   170: astore_2
      //   171: invokestatic obtain : ()Landroid/os/Message;
      //   174: astore #4
      //   176: aload #4
      //   178: aload_2
      //   179: putfield obj : Ljava/lang/Object;
      //   182: aload #4
      //   184: iconst_1
      //   185: putfield what : I
      //   188: aload_0
      //   189: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   192: invokestatic V0 : (Lcom/github/catvod/spider/merge/qd;)Landroid/os/Handler;
      //   195: aload #4
      //   197: invokevirtual sendMessage : (Landroid/os/Message;)Z
      //   200: pop
      //   201: aload_3
      //   202: invokevirtual close : ()V
      //   205: goto -> 240
      //   208: aload_0
      //   209: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   212: invokestatic V0 : (Lcom/github/catvod/spider/merge/qd;)Landroid/os/Handler;
      //   215: iconst_3
      //   216: invokevirtual sendEmptyMessage : (I)Z
      //   219: pop
      //   220: goto -> 240
      //   223: astore_2
      //   224: aload_2
      //   225: invokevirtual printStackTrace : ()V
      //   228: aload_0
      //   229: getfield h : Lcom/github/catvod/spider/merge/qd;
      //   232: invokestatic V0 : (Lcom/github/catvod/spider/merge/qd;)Landroid/os/Handler;
      //   235: iconst_2
      //   236: invokevirtual sendEmptyMessage : (I)Z
      //   239: pop
      //   240: return
      // Exception table:
      //   from	to	target	type
      //   0	71	223	java/io/IOException
      //   71	78	108	java/io/IOException
      //   78	85	108	java/io/IOException
      //   90	98	108	java/io/IOException
      //   101	105	108	java/io/IOException
      //   110	115	223	java/io/IOException
      //   115	162	223	java/io/IOException
      //   165	171	223	java/io/IOException
      //   171	205	223	java/io/IOException
      //   208	220	223	java/io/IOException
    }
  }
}


/* Location:              /Users/hetaiyi/Desktop/my/tech/java/study/aa/temp/temp.jar!/com/github/catvod/spider/merge/qd.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */